#include "gui/gui.h"

#include "gamestate.h"
#include "player.h"
#include "resourcemanager.h"

#include "entities/entity.h"

#include "gui/button.h"
#include "gui/buttonpanel.h"
#include "gui/datapanel.h"
#include "gui/guimessage.h"
#include "gui/cardpanel.h"
#include "gui/toppanel.h"

#include "renderer/renderer.h"

GUI* gui;

GUI::GUI():Widget(){
    BuildGUI();
}

void GUI::Initialise(int width, int height){
    SetWidth(width);
    SetHeight(height);
}

void GUI::Draw(){
    for(const auto & child:children){
        child->Draw();
    }
}

void GUI::Pick(){
    for(const auto & child:children){
        child->Pick();
    }
}

void GUI::Update(){
//    topPanel->SetActivePlayer(simulation->ActivePlayer());
}

void GUI::EndTurn(){
//    notifm.EndTurn();
}

void GUI::BuildGUI(){
    Entity* selected_entity = gamestate->GetSelectedEntity();

    CardPanel* bottom_book;

    if((bottom_book = static_cast<CardPanel*>(GetChild("bottom_book"))) == nullptr){
        std::unique_ptr<CardPanel> temp(new CardPanel());
        temp->SetName("bottom_book");
        bottom_book = temp.get();
        AddChild(std::move(temp));
    }

    if(selected_entity){
        bottom_book->Populate(selected_entity);
    }


//    panel = std::unique_ptr<Panel>(new Panel(FORM));
//    panel->AddChild(std::unique_ptr<Button>(new Button("1")));
//    panel->AddChild(std::unique_ptr<Button>(new Button("2")));
//    panel->AddChild(std::unique_ptr<Button>(new Button("3")));
//    panel->AddChild(std::unique_ptr<Button>(new Button("4")));
//    panel->AddChild(std::unique_ptr<Button>(new Button("5")));
//    panel->AddChild(std::unique_ptr<Button>(new Button("6")));
//    panel->Setx(500);
//    panel->Sety(500);
//    AddChild(std::move(panel));
}

GUIMessage* GUI::ProcessMessage(GUIMessage* message){
    return message;
}
